package com.ldx.blog.controller;

import com.ldx.blog.common.exception.BlogException;
import com.ldx.blog.pojo.request.AddBlogRequest;
import com.ldx.blog.pojo.request.UpdateBlogRequest;
import com.ldx.blog.pojo.response.BlogInfoResponse;
import com.ldx.blog.sevice.BlogService;
import com.ldx.blog.sevice.impl.BlogServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogInfoController {
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList() {
        return blogService.getList();
    }
    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(Integer blogId){
        log.info("getLogDetail:"+blogId);
        return blogService.getBlogDetail(blogId);
    }
    @RequestMapping("/add")
    public Boolean add(@RequestBody @Validated AddBlogRequest addBlogRequest) throws BlogException {
        return blogService.add(addBlogRequest);
    }
    @RequestMapping("/update")
    public Boolean updateBlog(@RequestBody @Validated UpdateBlogRequest updateBlogRequest) throws BlogException{
        log.info("执行更新 blog:{}",updateBlogRequest);
        return blogService.updateBlog(updateBlogRequest);
    }
    @RequestMapping("/delete")
    public Boolean deleteBlog(Integer blogId) throws BlogException {
        log.info(" deleteBlog接收参数:{}",blogId);
        return blogService.deleteBlog(blogId);
    }
}